package com.jiutong.meipenggang.http.present;

import android.content.Context;

import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.BaseBean;
import com.jiutong.meipenggang.entity.GestureLoginBean;
import com.jiutong.meipenggang.entity.LoginBean;
import com.jiutong.meipenggang.http.model.interfaces.GestureBiz;
import com.jiutong.meipenggang.http.model.requests.UserInfoRequest;
import com.jiutong.meipenggang.http.subscribers.ProgressSubscriber;
import com.jiutong.meipenggang.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipenggang.utils.EncryptUtil;
import com.jiutong.meipenggang.utils.SpConfig;
import com.jiutong.meipenggang.utils.TimeUitl;

import java.util.HashMap;

/**
 * @author Veken
 * @date on 2017/12/27 9:54
 * @describe
 */

public class GesturePresent {

    private Context mContext;
    private UserInfoRequest userInfoRequest;
    private GestureBiz gestureBiz;

    public GesturePresent(Context mContext, GestureBiz gestureBiz) {
        this.mContext = mContext;
        this.gestureBiz = gestureBiz;
        userInfoRequest = new UserInfoRequest();
    }

    /**
     * 手势密码登录
     */
    public void gestureLogin() {

        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<GestureLoginBean>() {
            @Override
            public void onNext(GestureLoginBean o) {
                gestureBiz.onSuccess(o);
            }

            @Override
            public void onError(Throwable e) {
                gestureBiz.onError(e);
            }
        };
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("OPT", 9);
        hashMap.put("handlePassword", EncryptUtil.encryptGesture3DES(gestureBiz.gesturePassword()));
        hashMap.put("gestureCipher", gestureBiz.gestureCipher());
        hashMap.put("timestamp", TimeUitl.getDate());
        userInfoRequest.gestureLogin(new ProgressSubscriber(onNextListener, mContext), hashMap);
    }

    /**
     * 手势密码登录
     */
    public void gestureChange() {
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseBean>() {
            @Override
            public void onNext(BaseBean o) {
                gestureBiz.onSuccess(o);
            }

            @Override
            public void onError(Throwable e) {
                gestureBiz.onError(e);
            }
        };
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("OPT", 8);
        hashMap.put("handlePassword", EncryptUtil.encryptGesture3DES(gestureBiz.gesturePassword()));
        hashMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        hashMap.put("token", SpConfig.getInstance().getString(Constants.TOKEN));
        hashMap.put("timestamp", TimeUitl.getDate());
        userInfoRequest.gestureChange(new ProgressSubscriber(onNextListener, mContext), hashMap);
    }


}
